//
//  RBGRangeViewController.m
//  BateauGenerique
//
//  Created by Florent Champigny on 09/06/2014.
//  Copyright (c) 2014 Kevin De Jesus Ferreira. All rights reserved.
//

#import "RBGRangeViewController.h"
#import "RBGFiltreController.h"
#import "RBGAppDelegate.h"

@interface RBGRangeViewController (){
    RBGAppDelegate *appDelegate;
}


@end


@implementation RBGRangeViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    appDelegate = (RBGAppDelegate *)[[UIApplication sharedApplication] delegate];

    self.range.minimumValue = [RBGAppDelegate minValue];
    
    self.range.maximumValue = [RBGAppDelegate maxValue] + 1;
    
    //valeur par defaut, affichées au debut
    self.range.lowerValue = self.range.minimumValue;
    self.range.upperValue =  self.range.maximumValue - 1;
    
    //ecart min entre les 2 boutons
    self.range.minimumRange = 1;

    [self updateSliderLabels];
    
}

-(void) viewDidAppear:(BOOL)animated
{
    [self.fondView setAlpha:self.alphaFond];
    [self.textPopUp setText:self.titrePopUp];



}

- (void) updateSliderLabels
{
    // You get get the center point of the slider handles and use this to arrange other subviews
    
    self.labelMin.text = [NSString stringWithFormat:@"%d", (int)self.range.lowerValue];
    
    if(self.range.upperValue <= self.range.maximumValue - 1)
    self.labelMax.text = [NSString stringWithFormat:@"%d", (int)self.range.upperValue];
    else
    self.labelMax.text = [NSString stringWithFormat:@"+"];

}

- (IBAction)rangeValueChanged:(id)sender {
    [self updateSliderLabels];
}
- (IBAction)valider:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
    [self.delegate receiveDonneesRBGRange:self.labelMin.text andNomModele:self.labelMax.text];
}

- (IBAction)annuler:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)cancelVie:(id)sender {
    
    if(self.cancelable)
    [self dismissViewControllerAnimated:YES completion:nil];

}
@end
